package com.xkdx.guangguang.fragment.brand;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.DiscountInfo;

public class BrandInfoNewsModule extends AbsModule {
	public List<DiscountInfo> newsInfoList;

	@Override
	public void parseData() throws Exception {
		try {
			backJson = (JSONArray) result;

			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getInfoListByBrand")) {
					newsInfoList = parseNewProductInfoList(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			// to do define a exception include all parseException
			throw e;
		}

	}
	
	private List<DiscountInfo> parseNewProductInfoList(JSONObject person)
			throws Exception {
		List<DiscountInfo> list = new ArrayList<DiscountInfo>();
		try {
			if (person == null) {
				return list;
			}
			JSONObject stut = (JSONObject) person.get("Result");
			JSONArray jsonArray = (JSONArray) stut.getJSONArray("ListInfo");
			JSONObject time = (JSONObject) stut.get("DetailInfo");

			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject item = (JSONObject) jsonArray.opt(i);
				DiscountInfo shopNewProduct = new DiscountInfo();
				shopNewProduct.setInfoID(item.getString("InfoID"));
				shopNewProduct.setInfoTitle(item.getString("InfoTitle"));
				shopNewProduct.setInfoType(item.getString("InfoType"));
				shopNewProduct.setPictrueUrl(item.getString("PictureUrl"));
				shopNewProduct.setBeginTime(item.getString("BeginTime"));
				shopNewProduct.setEndTime(item.getString("EndTime"));
				shopNewProduct.setLatestInfoTime(time.getString("RefreshTime"));
				list.add(shopNewProduct);
			}

		} catch (Exception e) {
			throw e;
		}
		return list;
	}

}
